package com.ruoyi.web.inventory.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.inventory.domain.InventoryClass;
import com.ruoyi.web.inventory.service.IInventoryClassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 存货分类Controller
 * 
 * @author ruoyi
 * @date 2024-08-19
 */
@RestController
@RequestMapping("/inventory/InventoryClass")
public class InventoryClassController extends BaseController
{
    @Autowired
    private IInventoryClassService inventoryClassService;

    /**
     * 查询存货分类列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:InventoryClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(InventoryClass inventoryClass)
    {
        startPage();
        List<InventoryClass> list = inventoryClassService.selectInventoryClassList(inventoryClass);
        return getDataTable(list);
    }

    /**
     * 导出存货分类列表
     */
    @PreAuthorize("@ss.hasPermi('inventory:InventoryClass:export')")
    @Log(title = "存货分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InventoryClass inventoryClass)
    {
        List<InventoryClass> list = inventoryClassService.selectInventoryClassList(inventoryClass);
        ExcelUtil<InventoryClass> util = new ExcelUtil<InventoryClass>(InventoryClass.class);
        util.exportExcel(response, list, "存货分类数据");
    }

    /**
     * 获取存货分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('inventory:InventoryClass:query')")
    @GetMapping(value = "/{cInvCCode}")
    public AjaxResult getInfo(@PathVariable("cInvCCode") String cInvCCode)
    {
        return success(inventoryClassService.selectInventoryClassByCInvCCode(cInvCCode));
    }

    /**
     * 新增存货分类
     */
    @PreAuthorize("@ss.hasPermi('inventory:InventoryClass:add')")
    @Log(title = "存货分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InventoryClass inventoryClass)
    {
        return toAjax(inventoryClassService.insertInventoryClass(inventoryClass));
    }

    /**
     * 修改存货分类
     */
    @PreAuthorize("@ss.hasPermi('inventory:InventoryClass:edit')")
    @Log(title = "存货分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InventoryClass inventoryClass)
    {
        return toAjax(inventoryClassService.updateInventoryClass(inventoryClass));
    }

    /**
     * 删除存货分类
     */
    @PreAuthorize("@ss.hasPermi('inventory:InventoryClass:remove')")
    @Log(title = "存货分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cInvCCodes}")
    public AjaxResult remove(@PathVariable String[] cInvCCodes)
    {
        return toAjax(inventoryClassService.deleteInventoryClassByCInvCCodes(cInvCCodes));
    }
}
